package work01;

import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class work6guessFist {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        ArrayList <Integer> historyList = new ArrayList<Integer>(); //1:剪刀 2:石头 3:布
        historyList.add(0);
        int count = 0;
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        while(true){
            int half = rand.nextInt(2)+1;//1 2
            int randomNum = rand.nextInt(3)+1; //1 2 3

            System.out.println("输入选择: 1:剪刀 2:石头 3:布");
            int choice = sc.nextInt();
            switch(choice){
                case 1: historyList.add(1);System.out.println("你的选择是:剪刀");break;
                case 2: historyList.add(2);System.out.println("你的选择是:石头");break;
                case 3: historyList.add(3);System.out.println("你的选择是:布");break;
                default: break;
            }
            for (Integer integer : historyList) {
                switch (integer) {
                    case 1:
                        count1++;
                        break;
                    case 2:
                        count2++;
                        break;
                    case 3:
                        count3++;
                        break;
                }
            }
            if(historyList.size() > 5) {
                if (count1 > count2 && count2 > count3) {
                    if (half == 1) {
                        System.out.println("你出的剪刀最多,调整策略");
                        randomNum = 2;
                    }
                } else if (count2 > count1 && count2 > count3) {
                    if (half == 1) {
                        System.out.println("你出的石头最多,调整策略");
                        randomNum = 3;
                    }
                } else if (count3 > count1 && count3 > count2) {
                    if (half == 1) {
                        System.out.println("你出的布最多,调整策略");
                        randomNum = 1;
                    }
                }
            }

            count1 = 0;
            count2 = 0;
            count3 = 0;

            switch(randomNum){
                case 1: System.out.println("系统选择:剪刀"); break;
                case 2: System.out.println("系统选择:石头"); break;
                case 3: System.out.println("系统选择:布"); break;
            }
            if(randomNum==1&&choice==1){
                System.out.println("平局");
            }else if(randomNum==2&&choice==2){
                System.out.println("平局");
            }else if(randomNum==3&&choice==3){
                System.out.println("平局");
            }else if(randomNum==1&&choice==2){
                count++;
                System.out.println("你赢了"+count+"局");
            }else if(randomNum==1&&choice==3){
                System.out.println("你输了");
            }else if(randomNum==2&&choice==1){
                System.out.println("你输了");
            }else if(randomNum==2&&choice==3){
                count++;
                System.out.println("你赢了"+count+"局");
            }else if(randomNum==3&&choice==1){
                count++;
                System.out.println("你赢了"+count+"局");
            }else if(randomNum==3&&choice==2){
                System.out.println("你输了");
            }

        }
    }
}
